const { ccclass, property, menu, requireComponent } = cc._decorator


/**
 * @description 精灵帧选择
 * @author mirahs
 * @email 2892727493@qq.com
 */
@ccclass
@requireComponent(cc.Sprite)
@menu("UI/SpriteFrameComp")
export default class SpriteFrameComp extends cc.Component {
    @property([cc.SpriteFrame])
    private frames: cc.SpriteFrame[] = []


    public setFrame(spName: string) {
        const frame = this.frames.find(value => { return value.name == spName })
        if (!frame) return

        this.node.getComponent(cc.Sprite).spriteFrame = frame
    }

    public setFrameByIndex(index: number) {
        if (index < 0 || index >= this.frames.length) return

        this.node.getComponent(cc.Sprite).spriteFrame = this.frames[index]
    }
}
